All Questions
Tagged with pythonunit-testing
67 questions
5votes
5answers
505views
How to test for performance regression?
I am working on a refactor on a certain package (I can give details if asked). The package involves a clever lazy evaluation of a sort of nested sequence of arithmetic operations. If the numerical ...
2votes
2answers
533views
Best practices for unit testing when breaking down functions into smaller ones
Say we have a function of the form def func(num: int) -> int: num = num + 1 num = 2 * num num = num**3 return num and let us act like each line is a long computation so that we ...
0votes
2answers
425views
What is a good unit testing strategy against a chain of public method calls?
say I have this code which is a chain of public methods, public_c calls public_b calls public_a def public_a(...): ... def public_b(...): ... public_a(...) def public_c(...): ... ...
-1votes
1answer
172views
Efficient way to write test cases depending on a Micro service
I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a ...
-1votes
1answer
128views
Software development in Python: unittests and assertions
I recently finished developing a piece of software in python where learning models and data processing procedures are contained within different class objects that succeed to each others (modules). As ...
2votes
2answers
343views
What is a good way to call a unit-tested function provided by a library/package?
Consider the function foo provided by package X in Python. I want to test the different functionalities of X.foo, and then use X.foo in my code. To make sure that I am using X.foo as it was tested, I ...
0votes
1answer
242views
How to properly isolate tests for dataframes with grouping?
I have the following problem: I would like to test complex business logic for each test case completely separately, i.e. all tests should run in parallel. I don't want the test for customer #43 to ...
14votes
3answers
3kviews
Should I choose repeated code in unit test or test logic? Can I avoid both?
When writing unit tests, I feel that there is a trade-off between code repetition and test logic. Example of my current (likely flawed) approach: To test this function (overly simple function for ...
-1votes
1answer
572views
How to write tests for a class that talks to a server without revealing connection implementation
I'm writing a class that acts as the interface to a server. The interface exposes a way to send messages to the server and pass messages back to the client through a callback. Implementations should ...
2votes
3answers
1kviews
Still don't understand when to mock and when not to
I've been trying to understand when to mock and when not to mock, however I'm not able to come up with a consistent guideline and I'm hoping to get some input on the subject. Let's look at the ...
0votes
1answer
1kviews
How to test a function with several conditional nested side effects
In Python, consider a function like the following: def main(*args): value1 = pure_function1(*args) if condition(value1): value = side_effect1(value1) if value: ...
1vote
3answers
1kviews
Should I unit test functions internally used by API I expose?
I'm writing a CRUD app in Python that exposes web API. At first I wrote functions for communicating with DB and wrote tests for these functions. def crud(): # do something with db def test_crud(): ...
2votes
1answer
2kviews
Should I check floating point values in a unit test?
We have unit tests that are running some underlying model. We provide it with some test input, and receive some outputs + floating point scores. What's a good practice from a unit-testing standpoint? ...
1vote
1answer
501views
Python Unit Tests Mocking Imports - Removing Dependencies for CI/CD
I have a project written in python that I would like to create unit tests on. This project has a dependency on a database project which is a sort of abstraction layer to data connections. The issue ...
1vote
1answer
393views
How to write tests in TDD for downloading and unpacking a file?
So I want to write this function that downloads a file and unpacks it in python using TDD. The function will look like this approximately import urllib.request import tarfile def download_and_unpack(...